#include "newtaskdialog.h"

#include <QLineEdit>
#include <QPushButton>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLabel>
#include <QFileDialog>

NewTaskDialog::NewTaskDialog(QWidget *parent)
    : QDialog(parent)
{
    QVBoxLayout *main_layout = new QVBoxLayout;

    QHBoxLayout *url_layout = new QHBoxLayout;
    QLabel *url_label = new QLabel(tr("URL:", "new download task dialog"));
    m_url = new QLineEdit(this);
    url_layout->addWidget(url_label);
    url_layout->addWidget(m_url);

    QHBoxLayout *file_layout = new QHBoxLayout;
    QLabel *file_label = new QLabel(tr("FILE:", "new download task dialog"));
    m_file = new QLineEdit(this);
    m_browse = new QPushButton(tr("browse", "new download task dialog"));
    file_layout->addWidget(file_label);
    file_layout->addWidget(m_file);
    file_layout->addWidget(m_browse);

    QHBoxLayout *control_layout = new QHBoxLayout;
    m_ok = new QPushButton(tr("ok", "new download task dialog"));
    m_cancel = new QPushButton(tr("cancel", "new download task dialog"));
    control_layout->addStretch();
    control_layout->addWidget(m_ok);
    control_layout->addWidget(m_cancel);

    main_layout->addLayout(url_layout);
    main_layout->addLayout(file_layout);
    main_layout->addLayout(control_layout);

    setLayout(main_layout);

    connect(m_ok, SIGNAL(clicked()), this, SLOT(accept()));
    connect(m_cancel, SIGNAL(clicked()), this, SLOT(reject()));
    connect(m_browse, SIGNAL(clicked()), this, SLOT(new_file()));
}

QString NewTaskDialog::get_url() const
{
    return m_url->text();
}

QString NewTaskDialog::get_file() const
{
    return m_file->text();
}

void NewTaskDialog::new_file()
{
    m_file->setText(QFileDialog::getSaveFileName(this));
}
